//
//  CPTabBarController.swift
//  CJPackDemo
//
//  Created by 陈警卫 on 2023-12-05.
//

import UIKit
import CJPack

class CPTabBarController: CJTabBarController {

    var homeNC: CPRootController {
        return ncTabBar(vc: CPHomeController(), title: "Home", image: "tab_discover")
    }
    
    var meNC: CPRootController {
        return ncTabBar(vc: CPMeController(), title: "Me", image: "tab_me")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupView()
        setupSkin()
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: false)
    }
    
    override func cj_skinAction(_ kit: Any) {
        super.cj_skinAction(kit)
        
        setupSkin()
    }
    
    func setupView() {
        viewControllers = [homeNC, meNC]
        selectedIndex = 0
    }
    
    func setupSkin() {
        if let vcs = viewControllers {
            for nc in vcs {
                nc.tabBarItem.image = nc.tabBarItem.image?
                    .cj_imageTint(color: CPColor.tabNormalModel.color)
                nc.tabBarItem.selectedImage = nc.tabBarItem.selectedImage?
                    .cj_imageTint(color: CPColor.tabSelectedModel.color)
            }
        }
        /**
         setupTabBarAppearance(backColor: CPColor.tabBackModel.color,
         normalColor: CPColor.tabNormalModel.color,
         selectedColor: CPColor.tabSelectedModel.color)         
         */
    }
    
    
    func ncTabBar(vc: UIViewController, title: String, image: String) -> CPRootController {
        let nc = CPRootController(rootViewController: vc)
        nc.tabBarItem.image = UIImage(named: image)?.cj_imageTint(color: CPColor.tabNormalModel.color)
        nc.tabBarItem.selectedImage = UIImage(named: image)?.cj_imageTint(color: CPColor.tabSelectedModel.color)
        
        nc.title = title
        vc.title = title
        return nc
    }

}
